package com.kfm.base.io.o;

import com.alibaba.fastjson.JSON;

import java.util.List;

public class Demo09 {

    public static void main(String[] args) {
        // JSON 数组  标识[]
//        String str = "[\"a\", \"b\", \"c\"]";
//
//        // jsonString --> obj
//        String[] strings = JSON.parseObject(str, String[].class);
//        System.out.println(Arrays.toString(strings));
//
//        // obj --> jsonString
//        String jsonString = JSON.toJSONString(strings);
//        System.out.println(jsonString);

        // json 对象数组
        String str = """
                [{
                  	"name": "秦爽",
                  	"score": 80.8,
                  	"gender": "男",
                  	"friend": {
                  		"name": "张兴成",
                  		"gender": "男"
                  	}
                  }, {
                  	"name": "秦二",
                  	"score": 90.8,
                  	"gender": "男"
                  }, {
                  	"name": "秦三",
                  	"score": 99.8,
                  	"gender": "男"
                  }]""";

        List<Student> students = JSON.parseArray(str, Student.class);

//        for (Student stu : students){
//            System.out.println(stu);
//        }

        // objArray --> str

        String jsonString = JSON.toJSONString(students);
        System.out.println(jsonString);
    }
}
